package com.cncsi.service;


import com.cncsi.dao.UserRepository;
import com.cncsi.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by liuyf90 on 2018/5/6.
 */
@Service
@Transactional
public class UserService implements UserDetailsService {
    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userRepository.findByUsername(username);
    }

    public List<User> getUserList(){
        List<User> userList = userRepository.findAll();
        return userList;
    }

    public User getUserForOne(Long id){
        User user = userRepository.findOne(id);
        return user;
    }


}